package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.CompanyDAO;
import entity.Company;

@WebServlet("/addcompany")
public class  AddCompanyServlet extends HttpServlet {
	private CompanyDAO companydao = new CompanyDAO();
	private String action;

	public AddCompanyServlet() {
		super();
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		Company_add(request);
		request.getRequestDispatcher("/companyList.jsp").forward(request, response);
	}

	private void Company_add(HttpServletRequest request) {
		try {
			Company fp=new Company();
			fp.setComno(request.getParameter("comno"));
			fp.setCcompany(request.getParameter("ccompany"));;
			fp.setAddress(request.getParameter("address"));
			fp.setPhone(request.getParameter("phone"));
			this.companydao.addCompany(fp);
	        
		 } catch (Exception ex) {
			 
	         request.setAttribute("errormsg", ex.getMessage());
	         
	     }
		
	}
}
